package pkmn.item;

public class TrainerItem implements Comparable<TrainerItem>{

    private Countable countable;
    private int quantity;

    /**
     * Constructor without quantity. (One item)
     * @param countable
     */
    public TrainerItem(Countable countable) {
        this.countable = countable;
        this.quantity = 1;
    }

    /**
     * Constructor with quantity
     * @param countable
     * @param quantity
     */
    public TrainerItem(Countable countable, int quantity) {
        this.countable = countable;
        this.quantity = quantity;
    }

    /**
     * Return the item
     * @return Countable
     */
    public Countable getCountable() {
        return this.countable;
    }

    /**
     * Get the quantity
     * @return int
     */
    public int getQuantity() {
        return this.quantity;
    }
    
    /**
     * Add itens. Return the quantity over 99.
     * @param quantity int
     * @return int
     */
    public int addQuantity(int quantity){
        int aux = this.quantity + quantity;
        if (aux > 99){
            this.quantity = 99;
            return aux - 99;
        }else{
            this.quantity = aux;
            return 0;
        }
    }

    public boolean equals(TrainerItem trainerItem){
        return trainerItem.getCountable().getClass().equals(this.countable.getClass());
    }

    /**
     * Compare two TrainerItem
     * @param trainerItem
     * @return int
     */
    public int compareTo(TrainerItem trainerItem){
        return trainerItem.getCountable().getClass().getSimpleName().compareTo(this.countable.getClass().getSimpleName());
    }

    @Override
    public String toString(){
        return this.countable.getClass().getSimpleName() + " (" + this.quantity + ")";
    }
}
